package com.xxgc.cloud.consumer.springcloudconsumer.controller;

import com.xxgc.cloud.api.result.Result;
import com.xxgc.common.quartz.job.ClearUserMembersJob;
import com.xxgc.common.quartz.utils.QuartzUtil;
import io.swagger.annotations.Api;
import org.quartz.SchedulerException;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @program: SpringCloudStudy
 * @description:
 * @author: Shijiayi
 * @create: 2022-12-06 14:05
 **/
@Api(tags = "任务")
@RestController
@RequestMapping("/task")
public class TaskController {

    @Resource
    private QuartzUtil qu;

    @PostMapping("/addTask")
    public Result addTask(@RequestParam String cron) throws SchedulerException {
        //一分钟执行一次任务
        qu.addJob("memberInspection","member","minuteTask","task",cron, ClearUserMembersJob.class);

        //同步一份到数据库

        return Result.success("创建成功");
    }

    @PostMapping("/delTask")
    public Result delTask() throws SchedulerException {
        qu.deleteJob("memberInspection","member","minuteTask","task");

        //更新任务状态

        return Result.success("删除成功");
    }

}
